package com.liu.complatableDemo;

import java.util.concurrent.*;

public class CompletableExample {
    public static void main(String[] args) {
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(
                2, 2, 2, TimeUnit.SECONDS, new LinkedBlockingDeque<>());
        CompletableFuture<Void> runAsync = CompletableFuture.runAsync(() ->
                System.out.println("Hello future"), threadPoolExecutor);
        System.out.println(runAsync.join());
        threadPoolExecutor.shutdown();

        System.out.println("--------------");

        CompletableFuture<Integer> integerCompletableFuture = CompletableFuture.supplyAsync(() -> 1).thenCombine(
                CompletableFuture.supplyAsync(() -> 2), Integer::sum
        );
        System.out.println(integerCompletableFuture.join());

        synchronized(CompletableExample.class){
            System.out.println(111);
        }

    }

}
